/**
 * 
 */
package com.fly.sms.adapter;

import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.fly.sms.CommonActivity;
import com.fly.sms.R;

public class LoginNameAdapter extends IAdapter {
	private List<String> list = null;

	public LoginNameAdapter(CommonActivity context,
			List<String> list) {
		super(context);
		this.list = list;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = context.getView(R.layout.loginnameitem);
		}
		final String name = list.get(position);
		TextView loginName = (TextView) convertView.findViewById(R.id.loginName);
		Button deleteBtn = (Button) convertView.findViewById(R.id.deleteBtn);
		loginName.setText(name);
		deleteBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				context.deleteName(name);
				list.remove(name);
				notifyDataSetChanged();
			}
		});
		return convertView;
	}
}
